package com.xhh.check.feign;

import com.xhh.check.service.CheckService;
import com.xhh.check.service.IUserIdentityService;
import com.xhh.check.service.ProvinceCityService;
import com.xhh.check.service.UnityService;
import com.xhh.model.check.pojos.ProvinceCity;
import com.xhh.model.check.pojos.Unity;
import com.xhh.model.check.pojos.UserIdentity;
import com.xhh.model.common.dtos.ResponseResult;
import com.xhh.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "身份校验相关接口")
@RestController
@RequestMapping("/check")
@RequiredArgsConstructor
public class CheckClient {

    private final CheckService checkService;
    private final ProvinceCityService provinceCityService;
    private final UnityService unityService;
//    private final IUserIdentityService userIdentityService;

    @ApiOperation("查询身份表")
    @GetMapping("{id}")
    public ResponseResult checkIdentity(@PathVariable("id") Long userId){
        return checkService.checkIdentity(userId);
    }

    @ApiOperation("获取省市列表")
    @GetMapping("/getProvinceCityLit")
    public ResponseResult getProCityList(){
        List<ProvinceCity> list = provinceCityService.list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("根据单位id获取单位信息")
    @GetMapping("/getUnityById/{unityId}")
    public ResponseResult getUnityById(@PathVariable("unityId") Long unityId){
        Unity unity = unityService.getById(unityId);
        return ResponseResult.okResult(unity);
    }

    @ApiOperation("根据单位编码获取单位信息")
    @GetMapping("/getUnityByCode/{uCode}")
    public ResponseResult getUnityByCode(@PathVariable("uCode") String uCode){
        return unityService.getUnityByCode(uCode);
    }

    @ApiOperation("根据用户id获取角色")
    @GetMapping("/getIdentity/{userId}")
    public ResponseResult getIdentity(@PathVariable("userId") Long userId){
        if (userId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        UserIdentity one = checkService.lambdaQuery()
                .eq(UserIdentity::getUserId, userId)
                .one();
        return ResponseResult.okResult(one);
    }

}
